/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */
func binaryTreePaths(root *TreeNode) []string {
    res := []string{}
    var traverse func (node *TreeNode, s string)
    traverse = func (node *TreeNode, s string) {
        if node.Left == nil && node.Right == nil {
            v := s + strconv.Itoa(node.Val)
            res = append(res, v)
            return
        }
        s = s + strconv.Itoa(node.Val) + "->"
        if node.Left != nil {
            traverse(node.Left, s)
        }
        if node.Right != nil {
            traverse(node.Right, s)
        }
    }
    traverse(root, "")
    return res
}
